﻿// java script chart v1.0.0, saturday Aug 09 17:00:00 CET 2008

// Copyright (c) 2008 
// Author: Xu ChangGong MSN:xuchanggong@hotmail.com GMail:xuchanggong@gmail.com
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Bar.prototype = new jsChart();
Bar.prototype.constructor = jsChart;
Bar.superclass = jsChart.prototype;

_obj_bar_uk_id=0;
function Bar(){}
var _oChart = Bar.prototype;
_oChart.BORDERCOLOR = '#d6d6d6';
_oChart.FRAMECOLOR = '#eeeeee';
_oChart.CNVCOLOR = '#ffffff';
_oChart.SCALECOLOR = '#000000';
_oChart.AXCOLOR = '#666666';
_oChart.GRIDCOLOR = '#d6d6d6';
_oChart.jsc_pageX = 0; 
_oChart.jsc_pageY = 0;
_oChart.Cursor="";
_oChart.Canvas={};
_oChart.ChartHint={};
_oChart.ChartGrid={};
_oChart.Canvasxlyr={};
_oChart.Canvasylyr={};
_oChart.Canvasoptslyr={};
_oChart.Canvascnvlyr={};
_oChart.canvasLeft = 60;
_oChart.canvasTop = 40;
_oChart.canvasRight = 5;
_oChart.canvasBottom = 60;
_oChart.drawWidth = 0;
_oChart.drawHeight = 0;
_oChart.XAxisTitle='';
_oChart.YAxisTitle='';
_oChart.dataMin = 0;
_oChart.dataMax = 0;
_oChart.axisLabels = [];
_oChart.barStatus = [];
_oChart.xDelta = 0;
_oChart.yDelta = 0;
_oChart.axisProperties = {};
_oChart.showLegend = true;

_oChart.drawChart = function() {
  this.Canvas=this.getDiv(this.canvasID);
  if (this.boder && this.boder.width) {
  	this.Canvas.style.borderWidth = this.boder.width;
		this.Canvas.style.borderColor = this.boder.color;
		this.Canvas.style.borderStyle = this.boder.style;
	}
  this.adjustCanvas();
	this.drawWidth=this.canvasWidth-this.canvasLeft;
	this.drawHeight=this.canvasHeight-this.canvasTop-this.canvasBottom;
	legendW = this.legend.itemWidth;
	legendH = this.legend.itemHeight;
	if (this.legend.placement==JSCHART_RIGHT || this.legend.placement==JSCHART_LEFT) {
		legendW = this.legend.itemWidth*this.legend.columnsNum+8*(this.legend.columnsNum-1);
		legendH = this.drawHeight;
		this.drawWidth -= legendW;
		if (this.legend.placement==JSCHART_RIGHT) {
			this.canvasRight = legendW;
			this.paint(this.Canvas,
				this.mkDiv(this.chartTitle, 'center', 0, 0, this.canvasWidth, this.canvasTop, '', this.canvasID+'Bartitle_0')+
				this.mkDiv('', '', this.canvasLeft, this.canvasTop+this.drawHeight+1, this.drawWidth+1, this.canvasBottom-30, '', this.canvasID+'xlyr', true)+
				this.mkDiv(this.XAxisTitle, 'center', this.canvasLeft, this.canvasTop+this.drawHeight+1+30, this.drawWidth+1, 30, '', this.canvasID+'btyr', true)+
				this.mkDiv('', 'right', 20, this.canvasTop, this.canvasLeft-20, this.drawHeight+1, '', this.canvasID+'ylyr', true)+
				this.mkDiv(this.YAxisTitle, 'right', 0, parseInt(this.drawHeight/3), 20, this.drawHeight+1, '', this.canvasID+'ltyr', true, true)+
				this.mkDiv('', '', this.canvasLeft+this.drawWidth+4, this.canvasTop, this.canvasRight, this.drawHeight, '', this.canvasID+'opts', true)
			);
		} else {
			this.canvasLeft += legendW;
			this.paint(this.Canvas,
				this.mkDiv(this.chartTitle, 'center', 0, 0, this.canvasWidth, this.canvasTop, '', this.canvasID+'Bartitle_0')+
				this.mkDiv('', '', this.canvasLeft, this.canvasTop+this.drawHeight+1, this.drawWidth+1, this.canvasBottom-30, '', this.canvasID+'xlyr', true)+
				this.mkDiv(this.XAxisTitle, 'center', this.canvasLeft, this.canvasTop+this.drawHeight+1+30, this.drawWidth+1, 30, '', this.canvasID+'btyr', true)+
				this.mkDiv('', 'right', legendW+20, this.canvasTop, this.canvasLeft-20-legendW, this.drawHeight+1, '', this.canvasID+'ylyr', true)+
				this.mkDiv(this.YAxisTitle, 'right', legendW, parseInt(this.drawHeight/3), 20, this.drawHeight+1, '', this.canvasID+'ltyr', true, true)+
				this.mkDiv('', '', 0, this.canvasTop, legendW, this.drawHeight, '', this.canvasID+'opts', true)
			);
		}
	} else {
		legendW = (this.drawWidth -= this.canvasRight);
		legendH = this.legend.itemHeight*this.legend.columnsNum+8*(this.legend.columnsNum-1);
		this.drawHeight = this.drawHeight-legendH;
		if (this.legend.placement==JSCHART_TOP) {
			this.canvasTop += legendH;
			this.paint(this.Canvas,
				this.mkDiv(this.chartTitle, 'center', 0, 0, this.canvasWidth, this.canvasTop, '', this.canvasID+'Bartitle_0')+
				this.mkDiv('', '', this.canvasLeft, this.canvasTop+this.drawHeight+1, this.drawWidth+1, this.canvasBottom-30, '', this.canvasID+'xlyr', true)+
				this.mkDiv(this.XAxisTitle, 'center', this.canvasLeft, this.canvasTop+this.drawHeight+1+30, this.drawWidth+1, 30, '', this.canvasID+'btyr', true)+
				this.mkDiv('', 'right', 20, this.canvasTop, this.canvasLeft-20, this.drawHeight+1, '', this.canvasID+'ylyr', true)+
				this.mkDiv(this.YAxisTitle, 'right', 0, parseInt(this.drawHeight/3), 20, this.drawHeight+1, '', this.canvasID+'ltyr', true, true)+
				this.mkDiv('', '', this.canvasTop-legendH, this.canvasLeft, this.drawWidth, legendH, '', this.canvasID+'opts', true)
			);
		} else {
			this.canvasBottom += legendH;
			this.paint(this.Canvas,
				this.mkDiv(this.chartTitle, 'center', 0, 0, this.canvasWidth, this.canvasTop, '', this.canvasID+'Bartitle_0')+
				this.mkDiv('', '', this.canvasLeft, this.canvasTop+this.drawHeight+1, this.drawWidth+1, this.canvasBottom-30-legendH, '', this.canvasID+'xlyr', true)+
				this.mkDiv(this.XAxisTitle, 'center', this.canvasLeft, this.canvasTop+this.drawHeight+1+30, this.drawWidth+1, 30, '', this.canvasID+'btyr', true)+
				this.mkDiv('', 'right', 20, this.canvasTop, this.canvasLeft-20, this.drawHeight+1, '', this.canvasID+'ylyr', true)+
				this.mkDiv(this.YAxisTitle, 'right', 0, parseInt(this.drawHeight/3), 20, this.drawHeight+1, '', this.canvasID+'ltyr', true, true)+
				this.mkDiv('', '', this.canvasLeft, this.canvasTop+this.drawHeight+1+30+30, this.drawWidth+1, legendH, '', this.canvasID+'opts', true)
			);
		}
	}
	xAxisProp = this.axisProperties.getXAxisProperties();
	yAxisProp = this.axisProperties.getYAxisProperties();
	if (this.axisProperties.isPlotHorizontal) {
		if (xAxisProp.userDefinedScale) {
			this.dataMin=xAxisProp.dataMin;
			this.dataMax=xAxisProp.dataMin+xAxisProp.scale*xAxisProp.numItems;
		}
		this.xDelta = (this.dataMax-this.dataMin)/this.drawWidth;
		this.yDelta = (this.axisLabels.length)/this.drawHeight;
	} else {
		if (yAxisProp.userDefinedScale) {
			this.dataMin=yAxisProp.dataMin;
			this.dataMax=yAxisProp.dataMin+yAxisProp.scale*yAxisProp.numItems;
		}
		this.xDelta = (this.axisLabels.length)/this.drawWidth;
		this.yDelta = (this.dataMax-this.dataMin)/this.drawHeight;
	}
	this.paint(this.Canvas,
		this.mkDiv('', '', this.canvasLeft, this.canvasTop, this.drawWidth+1, this.drawHeight+1, this.CNVCOLOR, this.canvasID+'bglyr')+
		this.mkDiv('', '', this.canvasLeft, this.canvasTop, this.drawWidth+1, this.drawHeight+1, '', this.canvasID+'gridlyr')+
		this.mkDiv('', '', this.canvasLeft, this.canvasTop, this.drawWidth+1, this.drawHeight+1, '', this.canvasID+'cnvlyr'), true
	);
	(o = (this.Canvascnvlyr = this.getDiv(this.canvasID+'cnvlyr')).style).zIndex = 2;
	o.cursor = 'crosshair';
	this.Canvasxlyr = this.getDiv(this.canvasID+'xlyr');
	this.Canvasylyr = this.getDiv(this.canvasID+'ylyr');
	this.ChartGrid = this.getDiv(this.canvasID+'gridlyr');
	this.Canvasoptslyr = this.getDiv(this.canvasID+'opts');
	this.ChartHint = this.getDiv('hinttip');
	this.ChartHint.style.visibility = 'hidden';
	this.ChartHint.style.zIndex = 1;
	this.mkScale();
	this.paint(this.Canvascnvlyr, '');
	this.barStatus.length=0;
	for (ind=0; ind<this.datas.length; ind++) {
	  for (lk=0; lk<this.datas[ind].length; lk++) {
	  	this.datas[ind][lk] = parseFloat(this.datas[ind][lk]);
	  }
		this.barStatus[ind] = true;
	}
	this.drawBars();
	this.drawLines();
	this.drawLegends();
}
_oChart.drawLines = function()
{
	_curveObj = this;
	resulthtm='';
	vnum=0;
	for (i=0; i<this.barStatus.length; i++) {
		if (this.barStatus[i])
			vnum++;
	}
	incNum = 1.0/(1.5*vnum+1);
	dind=0;
	for (a=0; a<this.legendLabels.length; a++) {
		if (this.barStatus[a]) {
			xPosition = [];
			yPosition = [];
			if (this.axisProperties.isPlotHorizontal) {
				for (ind=0; ind<this.axisLabels.length; ind++) {
					yPosition[yPosition.length]=ind-incNum*(dind*1.5+1.5)+1;
				}
				xPosition=this.datas[a];
			} else {
				for (ind=0; ind<this.axisLabels.length; ind++) {
					xPosition[xPosition.length]=ind+incNum*(dind*1.5+1.5);
				}
				yPosition=this.datas[a];
			}
    	resulthtm += this.drawPolyLine(xPosition, yPosition, this.paints[a], this.legendLabels[a]);
    	dind++;
    }
	}
	this.paint(this.Canvascnvlyr, resulthtm, true);	
}
_oChart.drawPolyLine = function(x, y, color, hintStr)
{
  linesHtm = '';
  j=0;
  cind=j;
  while (j<x.length-1) {
    if (y[cind]=='' || y[cind]=='0') {
      j++;
      cind=j;
    } else {
      break;
    }
  }
  while (j<x.length-1) {
    if (y[j+1]=='' || y[j+1]=='0') {
      j++;
      continue;
    }
    linesHtm += this.mkLin(x[cind], y[cind], x[j+1], y[j+1], color);
    linesHtm += this.fillOval(x[cind], y[cind],6,6, (hintStr ? hintStr+'<br>'+this.XAxisTitle+': '+this.axisLabels[cind]+'<br>'+this.YAxisTitle+': '+y[cind] : ''), color, cind);
    j++;
    cind=j;
  }
  linesHtm += this.fillOval(x[cind], y[cind], 6, 6, (hintStr ? hintStr+'<br>'+this.XAxisTitle+': '+this.axisLabels[cind]+'<br>'+this.YAxisTitle+': '+y[cind] : ''), color, cind);
	return linesHtm;
};
_oChart.fillOval = function(left, top, w, h, s, color, ind)
{
	var xMax = 0, xMin = 0, yMax = 0, yMin = 0;
	if (this.axisProperties.isPlotHorizontal) {
		xMax = this.dataMax;
		xMin = this.dataMin;
		yMax = this.axisLabels.length-1; 
		yMin = 0;
	} else {
		yMax = this.dataMax;
		yMin = this.dataMin;
		xMax = this.axisLabels.length-1; 
		xMin = 0;
	}
	left = Math.round((left-xMin)/this.xDelta);
	if (left<-1 || left>this.drawWidth)
	  return'';
	left = left-2;
	top = this.drawHeight+Math.round((yMin-top)/this.yDelta);
	if (top<-1 || top>this.drawHeight)
	  return'';
	top = top -2;
	CirleHtm = '';
	var a = (w -= 1)>>1, b = (h -= 1)>>1,
	wod = (w&1)+1, hod = (h&1)+1,
	cx = left+a, cy = top+b,
	x = 0, y = b,
	ox = 0, oy = b,
	aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
	st = (aa2>>1)*(1-(b<<1)) + bb,
	tt = (bb>>1) - aa2*((b<<1)-1),
	pxl, dw, dh;
	if (w+1) while (y > 0)
	{
		if (st < 0)
		{
			st += bb*((x<<1)+3);
			tt += (bb<<1)*(++x);
		}
		else if (tt < 0)
		{
			st += bb*((x<<1)+3) - aa4*(y-1);
			pxl = cx-x;
			dw = (x<<1)+wod;
			tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3);
			dh = oy-y;
			CirleHtm += this.mkDiv('', '', pxl, cy-oy, dw, dh, color, '', false, true);
			CirleHtm += this.mkDiv('', '', pxl, cy+y+hod, dw, dh, color, '', false, true);
			ox = x;
			oy = y;
		}
		else
		{
			tt -= aa2*((y<<1)-3);
			st -= aa4*(--y);
		}
	}
	CirleHtm += this.mkDiv('<A onmouseover="_curveObj.hintTip(this,\''+s+'\')" onmouseout="_curveObj.hintTip(this,\'\')" href="javascript:void(0);">&nbsp;&nbsp;&nbsp;</A>', '', cx-a, cy-oy, w+1, (oy<<1)+hod, color, '', false, true);
	return CirleHtm;
}
_oChart.mkLin = function(x1, y1, x2, y2, lcolor)
{
	if (x1 > x2)
	{
		var _x2 = x2;
		var _y2 = y2;
		x2 = x1;
		y2 = y1;
		x1 = _x2;
		y1 = _y2;
	}
	var xMax = 0, xMin = 0, yMax = 0, yMin = 0;
	if (this.axisProperties.isPlotHorizontal) {
		xMax = this.dataMax;
		xMin = this.dataMin;
		yMax = this.axisLabels.length-1; 
		yMin = 0;
	} else {
		yMax = this.dataMax;
		yMin = this.dataMin;
		xMax = this.axisLabels.length-1; 
		xMin = 0;
	}
  x1 = Math.round((x1-xMin)/this.xDelta);
  y1 = this.drawHeight+Math.round((yMin-y1)/this.yDelta);
  x2 = Math.round((x2-xMin)/this.xDelta);
  y2 = this.drawHeight+Math.round((yMin-y2)/this.yDelta);
  if (x1<0 && x2<0) {
    return '';
  } else if (x1>this.drawWidth  && x2>this.drawWidth) {
    return '';
  } else if (x1<0) {
    y1 = Math.round(0*(y2-y1)/(x2-x1)+y1-x1*((y2-y1)/(x2-x1)));
    x1 = 0;
  } else if (x2>this.drawWidth) {
    y2 = Math.round(this.drawWidth*(y2-y1)/(x2-x1)+y1-x1*((y2-y1)/(x2-x1)));
    x2 = this.drawWidth;
  }
  if (y1<0 && y2<0) {
    return '';
  } else if (y1>this.drawHeight && y2>this.drawHeight) {
    return '';
  } else  if (y1<0) {
    x1 = Math.round((0-(y1-x1*((y2-y1)/(x2-x1))))/((y2-y1)/(x2-x1)));
    y1 = 0;
  } else if (y2>this.drawHeight) {
    x2 = Math.round((this.drawHeight-(y1-x1*((y2-y1)/(x2-x1))))/((y2-y1)/(x2-x1)));
    y2 = this.drawHeight;
  }
  lineHtm = '';
	var dx = x2-x1, dy = Math.abs(y2-y1),
	x = x1, y = y1,
	yIncr = (y1 > y2)? -1 : 1;
	var s = 2;
	if (dx >= dy)
	{
		if (dx > 0 && s-3 > 0)
		{
			var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s>>1)*dy) / dx;
			_s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
		}
		else var _s = s;
		var ad = Math.ceil(s/2);

		var pr = dy<<1,
		pru = pr - (dx<<1),
		p = pr-dx,
		ox = x;
		while ((dx--) > 0)
		{
			++x;
			if (p > 0)
			{
				lineHtm += this.mkDiv('', '', ox, y, x-ox+ad, _s, lcolor, '', false, true);
				y += yIncr;
				p += pru;
				ox = x;
			}
			else p += pr;
		}
		lineHtm += this.mkDiv('', '', ox, y, x2-ox+ad+1, _s, lcolor, '', false, true);
	}
	else
	{
		if (s-3 > 0)
		{
			var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s>>1)*dx-dy) / dy;
			_s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
		}
		else var _s = s;
		var ad = Math.round(s/2);

		var pr = dx<<1,
		pru = pr - (dy<<1),
		p = pr-dy,
		oy = y;
		if (y2 <= y1)
		{
			++ad;
			while ((dy--) > 0)
			{
				if (p > 0)
				{
					lineHtm += this.mkDiv('', '', x++, y, _s, oy-y+ad, lcolor, '', false, true);
					y += yIncr;
					p += pru;
					oy = y;
				}
				else
				{
					y += yIncr;
					p += pr;
				}
			}
			lineHtm += this.mkDiv('', '', x2, y2, _s, oy-y2+ad, lcolor, '', false, true);
		}
		else
		{
			while ((dy--) > 0)
			{
				y += yIncr;
				if (p > 0)
				{
					lineHtm += this.mkDiv('', '', x++, oy, _s, y-oy+ad, lcolor, '', false, true);
					p += pru;
					oy = y;
				}
				else p += pr;
			}
			lineHtm += this.mkDiv('', '', x2, oy, _s, y2-oy+ad+1, lcolor, '', false, true);
		}
	}
	return lineHtm;
}
_oChart.drawBars = function()
{
	_BarObj = this;
	
	for (ind=this.barStatus.length; ind<this.datas.length; ind++) {	
		this.barStatus[ind] = true
	}
	resulthtm='';
	vnum=0;
	for (i=0; i<this.barStatus.length; i++) {
		if (this.barStatus[i])
			vnum++;
	}
	incNum = 1.0/(1.5*vnum+1);
	dind=0;
	for (i=0; i<this.legendLabels.length; i++) {
		if (this.barStatus[i]) {
			for (ind=0; ind<this.axisLabels.length; ind++) {
				_x=0; _y=0; _w=0; _h=0;
				if (this.axisProperties.isPlotHorizontal) {
					_x=0;
					_y=ind-incNum*(dind*1.5+1)+1;
					_w=this.datas[i][ind];
					_h=incNum;
				} else {
					_y=this.datas[i][ind];
					_x=ind+incNum*(dind*1.5+1);
					_h=_y;
					_w=incNum;
				}
    		resulthtm+=this.drawRect('', _x, _y, _w, _h, this.paints[i], '',this.legendLabels[i]+'\r'+this.XAxisTitle+': '+(this.axisProperties.isPlotHorizontal ? this.datas[i][ind] : this.axisLabels[ind])+'\r'+this.YAxisTitle+': '+(!this.axisProperties.isPlotHorizontal ? this.datas[i][ind] : this.axisLabels[ind]),'cursor:pointer;');
			}
			dind++;
		}
	}
	this.paint(this.Canvascnvlyr, resulthtm, true);	
}
_oChart.drawLegends = function()
{
	eval('_BarObj_'+_obj_bar_uk_id+' = this');
	for (a=0; a<this.legendLabels.length; a++) {
  	_ccnum = a%this.legend.columnsNum;
  	_cccol = parseInt(a/this.legend.columnsNum);
  	_clix = (this.legend.placement == JSCHART_RIGHT || this.legend.placement == JSCHART_LEFT ? _ccnum*(this.legend.itemWidth+5) : _cccol*(this.legend.itemWidth+5));
  	_cliY = (this.legend.placement == JSCHART_RIGHT || this.legend.placement == JSCHART_LEFT ? _cccol*(this.legend.itemHeight+5) : _ccnum*(this.legend.itemHeight+5));
  	_color = this.barStatus[a] ? this.paints[a] : '#FFFFFF';
		this.paint(this.Canvasoptslyr, this.mkDiv('<font style="font-size:11px;font-family:Arial,Helvetica,sans-serif;color:black;">'+this.legendLabels[a]+'<\/font>', 'center', _clix, _cliY, this.legend.itemWidth, this.legend.itemHeight, _color, 'chartLegend_'+_obj_bar_uk_id+'_'+a, false, true,'','','cursor:pointer;'), true);
		chartLegend = this.getDiv('chartLegend_'+_obj_bar_uk_id+'_'+a);
		chartLegend.onclick=function() {
			secids=this.id.split('_');
			eval('_BarObj=_BarObj_'+secids[secids.length-2]);
			_BarObj.barStatus[secids[secids.length-1]]=!(_BarObj.barStatus[secids[secids.length-1]]);
			this.style.background='#'+(_BarObj.barStatus[secids[secids.length-1]] ? _BarObj.paints[secids[secids.length-1]] : 'FFFFFF');
			_BarObj.paint(_BarObj.Canvascnvlyr, '');
			_BarObj.drawBars();
			_BarObj.drawLines();
		}
	}
	_obj_bar_uk_id++;
}
_oChart.drawRect = function(txt, x, y, w, h, c, id, titleText,addStyle)
{
  x = this.scaleX(x);
 	y = this.scaleY(y);
 	w=w/this.xDelta;
 	h=h/this.yDelta;
 	return this.mkDiv(txt, 'left', x, y, w, h, c, id, false, true,false,titleText,addStyle);
}
_oChart.scaleY = function(y)
{
	return (Math.min(Math.max(this.drawHeight+Math.round(((this.axisProperties.isPlotHorizontal ? 0 : this.dataMin)-y)/this.yDelta), -1), this.drawHeight+1));
}
_oChart.scaleX = function(x)
{
	return (Math.min(Math.max(Math.round((x-(this.axisProperties.isPlotHorizontal ? this.dataMin : 0))/this.xDelta), -1), this.drawWidth+1));
}
_oChart.mkScale = function() {
	xAxisProp = this.axisProperties.getXAxisProperties();
	yAxisProp = this.axisProperties.getYAxisProperties();
	var ivy = 1, ivx = 1, xMax = 0, xMin = 0, yMax = 0, yMin = 0;
	if (this.axisProperties.isPlotHorizontal) {
		if (xAxisProp.userDefinedScale) {
			ivx = xAxisProp.scale;
		} else {
			ivx = this.mkIv(this.dataMax-this.dataMin, this.drawWidth);
		}
		xMax = this.dataMax;
		xMin = this.dataMin;
		yMax = this.axisLabels.length; 
		yMin = 0;
	} else {
		if (yAxisProp.userDefinedScale) {
			ivy = yAxisProp.scale;
		} else {
			ivy = this.mkIv((this.dataMax-this.dataMin)*this.drawWidth/this.drawHeight, this.drawHeight);
		}
		yMax = this.dataMax;
		yMin = this.dataMin;
		xMax = this.axisLabels.length; 
		xMin = 0;
	}
	var rx = ivx/this.xDelta, ry = ivy/this.yDelta,
	htm = '', gridhtm = '',
	pos, str, strs, strl,
	limt = Math.round(xMax/this.xDelta), limb = Math.round(xMin/this.xDelta),
	j = Math.ceil(xMin/ivx),
	i = Math.round(j*rx);
	while (i-limt <= 0)
	{
		str = this.axisProperties.isPlotHorizontal ? (''+this.mkNumStr(j, ivx, true)) : (this.axisLabels[parseInt(''+this.mkNumStr(j, ivx, true))]);
		if (!str) str='';
		strl = str.length;
		pos = i-limb;
		htm += (xAxisProp.showTicks==TICKS_NONE ? '' : this.mkDiv('', '', pos, 0, 1, 4, this.SCALECOLOR, '', false, true))+
			this.mkDiv('<font style="font-size:11px;font-family:Arial,Helvetica,sans-serif;color:black;">'+str+'<\/font>', '', pos-3*strl+(this.axisProperties.isPlotHorizontal ? 0 : 1/this.xDelta/2), 4, 16*strl, 12, '', '', true, false);
		gridhtm += (xAxisProp.showGridLines==GRID_LINES_NONE && j ? '' : this.mkDiv('', '',  pos, 0, 1, this.drawHeight+1, !j? this.AXCOLOR : this.GRIDCOLOR, '', false, true));
		i = Math.round(++j*rx);
	}
	this.paint(this.Canvasxlyr, htm);
	var sclw = parseInt(this.Canvasylyr.style.width);
	htm = '';
	limt = Math.round(yMax/this.yDelta), limb = Math.round(yMin/this.yDelta);
	j = Math.ceil(yMin/ivy);
	i = Math.round(j*ry);
	while (i-limt <= 0)
	{
		str = (!this.axisProperties.isPlotHorizontal ? ''+this.mkNumStr(j, ivy, true) : this.axisLabels[parseInt(''+this.mkNumStr(j, ivy, true))]);
		if (!str) str='';
		strl = str.length;
		pos = this.drawHeight-i+limb;
		htm += (yAxisProp.showTicks==TICKS_NONE ? '' : this.mkDiv('', '', sclw-4, pos, 4, 1, this.SCALECOLOR, '', false, true))+
			this.mkDiv('<font style="font-size:11px;font-family:Arial,Helvetica,sans-serif;color:black;">'+str+'<\/font>', 'right', 0, pos-7-(this.axisProperties.isPlotHorizontal ? 1/this.yDelta/2 : 0), sclw-6, 12, '', '', true, false);
		gridhtm += (yAxisProp.showGridLines==GRID_LINES_NONE && j ? '' : this.mkDiv('', '',  0, pos, this.drawWidth+1, 1, !j? this.AXCOLOR : this.GRIDCOLOR, '', false, true));
		i = Math.round(++j*ry);		
	}
	this.paint(this.Canvasylyr, htm);
	this.paint(this.ChartGrid, gridhtm);
}
_oChart.mkIv = function(x, totalNum)
{
	x *= totalNum/this.drawWidth;
	var i = 0;
	while (x-100 <= 0)
	{
		x *= 10;
		i++;
	}
	while (x-1000 > 0)
	{
		x /= 10;
		i--;
	}
	x = Math.floor(x);
	x = (x-600 >= 0)? 100 : (x-300 >= 0)? 50 : (x-200 >= 0)? 25 : 20;
	while (i < 0)
	{
		x = parseInt(x += '0');
		i++;
	}
	return parseFloat(this.shiftL(x, i));
}
_oChart.hintTip = function(obj, hintText)
{
	var x = 0, y = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			x += obj.offsetLeft;
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		x += obj.x;
		y += obj1.y;
	}
	if (this.jsc_ie || this.jsc_kq)
	{
		x += this.jsc_db.scrollLeft-(this.jsc_ie && !this.jsc_iemac)*2;
		y += this.jsc_db.scrollTop-(this.jsc_ie && !this.jsc_iemac)*2;
	}
	this.ChartHint.style.left = (x+16)+'px';
	this.ChartHint.style.top = (y+22)+'px';
	this.paint(this.ChartHint,
		'<small style="background:'+this.CNVCOLOR+';white-space:nowrap;">'+hintText+'<\/small>',
		false
	);
	if (this.ChartHint.style.visibility == 'hidden') 
		this.ChartHint.style.visibility = 'visible';
	else 
		this.ChartHint.style.visibility = 'hidden';
}
_oChart.shiftL = function(x, n)
{
	var neg = (x < 0)? '-' : '';
	x = ''+Math.abs(x);
	while (n--)
	{
		if (x.charAt(x.length-1) == '0')
			x = x.substring(0, x.length-1);
		else if (!(/\./).test(x))
			x = x.substring(0, x.length-1)+'.'+x.charAt(x.length-1);
		else if (!x.indexOf('.'))
			x = '.0'+x.substring(1);
		else x = x.substring(0, x.indexOf('.')-1)+'.'+x.charAt(x.indexOf('.')-1)+x.substring(x.indexOf('.')+1);
	}
	if (x.charAt(0) == '.') x = '0'+x;
	return neg+x;
}
String.prototype.toExp = function()
{
	var neg = (this.charAt(0) == '-')*1;
	var n = this.match(/[1-9]/g).length;
	if (Math.abs(parseFloat(this)) > 1)
		return this.substring(0,neg+1) + ((n-1)? ('.'+this.substring(neg+1, this.indexOf('0'))) : '') + '*10<sup>' + (this.length-1-neg) + '<\/sup>';
	return (neg? '-' : '') + this.match(/[1-9]/)[0] + ((n-1)? ('.'+this.substring(this.length-n+1)) : '') + '*10<sup>-' + (this.substring(this.indexOf('.')+1).length-n+1) + '<\/sup>';
}
_oChart.mkNumStr = function(n, iv, toE, toI)
{
	var i = 0;
	if (!n || !iv) return (toI ? g_yz : '0');
	while (Math.abs(iv)-1 < 0)
	{
		iv *= 10;
		i++;
	}
	n = this.shiftL(!toE? Math.round(n*iv) : (n*iv), i);
	if (toI) {
	  n = g_yz-n+g_ya;
	}
	return (toE && n.length > 6) ? n.toExp() : n;
}
AxisProperties = function(blph) {
	this.isPlotHorizontal = blph;
	this.dataProperties = {};
	this.labelProperties = {};
}
AxisProperties.prototype.getXAxisProperties = function () {
	return this.isPlotHorizontal ? this.dataProperties : this.labelProperties;
}
AxisProperties.prototype.getYAxisProperties = function () {
	return this.isPlotHorizontal ? this.labelProperties : this.dataProperties;
}
LabelProperties = function() {
	this.showTicks = TICKS_ALL;
	this.showGridLines = GRID_LINES_ALL;
}
DataProperties.prototype = new LabelProperties();
DataProperties.prototype.constructor = LabelProperties;
DataProperties.superclass = LabelProperties.prototype;
function DataProperties(){}
var _oDataProperties = DataProperties.prototype;
_oDataProperties.userDefinedScale=false;
_oDataProperties.dataMin=0;
_oDataProperties.numItems = 5;
_oDataProperties.scale = 1;
_oDataProperties.usePercentSigns=false;
_oDataProperties.setUserDefinedScale = function(x, n, m) {
	this.userDefinedScale=true;
	this.scale = n
	this.dataMin = x;
	this.numItems = m;
}